import React, { Component } from 'react'
import qs from 'qs'

const DetailData = [
  {id: '01', title: '消息1', content: '你好，中国'},
  {id: '02', title: '消息2', content: '你好，尚硅谷'},
  {id: '03', title: '消息3', content: '你好，未来的自己'}
]
export default class Detail extends Component {
  render() {
    console.log('##props', this.props)
    // 接收params参数
    // const {id, title} = this.props.match.params
    
    // 接收search参数
    //urlencoded编码
    // let obj = {name: 'tom', age: '18'}
    // console.log(qs.stringify(obj))
    // let str = 'car=奔驰&price=199'
    // console.log(qs.parse(str))
    const {search} = this.props.location
    const {id, title} = qs.parse(search.slice(1))

    const findResult = DetailData.find(w => w.id === id)
    return (
      <ul>
        <li>ID: {id}</li>
        <li>title: {title}</li>
        <li>content: {findResult?.content}</li>
      </ul>
    )
  }
}
